package bb.lanxing.chart.sample;

import java.util.List;

import bb.lanxing.chart.sample.result.LushuPointSampleResult;
import bb.lanxing.chart.sample.result.i.ISampleResult;
import bb.lanxing.model.database.IRouteBookPoint;

public class LushuPointDistanceSample extends LineChartDataDistanceSample<IRouteBookPoint> {
    private int maxAltitudeIndex = -1;
    private int minAltitudeIndex = -1;
    protected double maxAltitude = Double.MIN_VALUE;
    protected double minAltitude = Double.MAX_VALUE;

    @Override
    public boolean ignoreDistance(IRouteBookPoint iRouteBookPoint, IRouteBookPoint iRouteBookPoint2) {
        return false;
    }

    @Override
    protected boolean isExtremaIndex(int i) {
        return i == this.maxAltitudeIndex || i == this.minAltitudeIndex;
    }

    @Override
    public void findExtremePoint(List<? extends IRouteBookPoint> list) {
        int size = list.size();
        for (int i = 0; i < size; i++) {
            IRouteBookPoint iRouteBookPoint = list.get(i);
            if (iRouteBookPoint != null) {
                if (iRouteBookPoint.getAltitude() > this.maxAltitude) {
                    this.maxAltitude = iRouteBookPoint.getAltitude();
                    this.maxAltitudeIndex = i;
                }
                if (iRouteBookPoint.getAltitude() < this.minAltitude) {
                    this.minAltitude = iRouteBookPoint.getAltitude();
                    this.minAltitudeIndex = -1;
                }
            }
        }
    }

    @Override
    public ISampleResult<IRouteBookPoint> sample(double d, List<? extends IRouteBookPoint> list, int i) {
        if (list.size() <= i) {
            findExtremePoint(list);
        }
        sampleData(d, list, i);
        LushuPointSampleResult lushuPointSampleResult = new LushuPointSampleResult();
        lushuPointSampleResult.setDistanceList(getSampledDistance());
        lushuPointSampleResult.setSampleDataSourceList(getSampleDataSource());
        lushuPointSampleResult.setMaxAltitude(this.maxAltitude);
        lushuPointSampleResult.setMinAltitude(this.minAltitude);
        return lushuPointSampleResult;
    }
}
